package com.hust360.percent.pojo;

import java.util.Comparator;

/**
 * 改类中定义了各种排序接口的实现
 * 
 * @author yangyang
 * 
 */
public class SortInterfaceImpls {

	/*
	 * DiscountInfo对象的排序接口的实现类
	 */
	/*----------------------------------------------------------------------------------------*/

	/**
	 * 根据折扣排序的接口的实现类
	 * 
	 * @author yangyang
	 * 
	 */
	public static class SortByDiscountImpl implements Comparator<DiscountInfo> {

		public SortByDiscountImpl() {
		}

		@Override
		public int compare(DiscountInfo lhs, DiscountInfo rhs) {
			int cmp = lhs.getDiscount().intValue()
					- rhs.getDiscount().intValue();
			int cmp2 = lhs.getDiscountType().intValue()
					- rhs.getDiscountType().intValue();
			return cmp != 0 ? cmp : cmp2;
		}
	}

	/**
	 * 根据人气排序的接口实现类
	 */
	public static class SortByLikeImpl implements Comparator<DiscountInfo> {
		@Override
		public int compare(DiscountInfo lhs, DiscountInfo rhs) {
			return (int) (lhs.getLiked().longValue() - rhs.getLiked()
					.longValue()) * (-1);
		}
	}

	/**
	 * 根据最新活动排序
	 */
	public static class LatestImpl implements Comparator<DiscountInfo> {
		@Override
		public int compare(DiscountInfo lhs, DiscountInfo rhs) {
			return -1 * lhs.getCreateDate().compareTo(rhs.getCreateDate());
		}
	}

	/**
	 * 根据距离排序
	 */
	public static class DistanceImpl implements Comparator<DiscountInfo> {
		@Override
		public int compare(DiscountInfo lhs, DiscountInfo rhs) {
			return (int) -(rhs.getDistance() - lhs.getDistance());
		}
	}

}
